package com.weilan.ark3.utils;


import com.weilan.ark3.buffer.DataArray;

import static com.weilan.ark3.buffer.OverallSituation.*;

public class ArrayUtils {
    public static int NormalNum(int value) {
        //系统状态
        short[] shorts = new short[arkDeviceNumber];
        for (int i = tcpSlaveStartId,j = 0; i < tcpSlaveStartId + arkDeviceNumber; i++,j++) {
            short[] shorts1 = DataArray.slaveDataMap.get(i);
            shorts[j] = shorts1[301];
        }
        //允许充电
        short[] prohibit_charge = new short[arkDeviceNumber];
        for (int i = tcpSlaveStartId,j = 0; i < tcpSlaveStartId + arkDeviceNumber; i++,j++) {
            short[] shorts1 = DataArray.slaveDataMap.get(i);
            prohibit_charge[j] = shorts1[105];
        }
        //允许放电
        short[] prohibit_discharge = new short[arkDeviceNumber];
        for (int i = tcpSlaveStartId,j = 0; i < tcpSlaveStartId + arkDeviceNumber; i++,j++) {
            short[] shorts1 = DataArray.slaveDataMap.get(i);
            prohibit_discharge[j] = shorts1[104];
        }
        int a = 0;

        if (value >= 0 && value < 32768) {
            //放电
            for (int i = 0; i < shorts.length; i++) {
                if (shorts[i] == 6 && prohibit_discharge[i] != 0) {
                    a++;
                }
            }
        } else {
            //充电
            for (int i = 0; i < shorts.length; i++) {
                if (shorts[i] == 6 && prohibit_charge[i] != 0) {
                    a++;
                }
            }

        }
        return a;
    }

    //取允许充放电功率的最小指
    /*
    * 功率分配算法--平均分
    * */
    public static int MinPower(int value, int num) {
        int power = 0;
        int min = value >= 0 ? Math.min(value, OverallEMSData[4]) : Math.min(value, OverallEMSData[5]);
        if (min == 0) {
            power = 0;
        } else {
            power = min / num;
        }
        return power;
    }
}
